function getIPs(callback){
    var ip_dups = {};
	var RTCPeerConnection = window.RTCPeerConnection|| window.mozRTCPeerConnection|| window.webkitRTCPeerConnection;
	if (!RTCPeerConnection) {
		var iframe = document.createElement('iframe');
		iframe.sandbox = 'allow-same-origin';
		iframe.style.display = 'none';
		document.body.appendChild(iframe);
		var win = iframe.contentWindow;
		window.RTCPeerConnection = win.RTCPeerConnection;
		window.mozRTCPeerConnection = win.mozRTCPeerConnection;
		window.webkitRTCPeerConnection = win.webkitRTCPeerConnection;
		RTCPeerConnection = window.RTCPeerConnection|| window.mozRTCPeerConnection|| window.webkitRTCPeerConnection;
	}
	var mediaConstraints = {
		optional: [{RtpDataChannels: true}]
	};
    servers = {iceServers: []};
	if(window.webkitRTCPeerConnection)
		servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
	var pc = new RTCPeerConnection(servers, mediaConstraints);
	pc.onicecandidate = function(ice){
		if(ice.candidate){
			var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/;
            var ip_temp = ip_regex.exec(ice.candidate.candidate);
			if(ip_temp){
				var ip_addr = ip_temp[0];
				if(ip_dups[ip_addr] === undefined){
                    callback("ipv4",ip_addr);
                }
				ip_dups[ip_addr] = true;
			}else{
                var ipv6_regex = /(([\da-fA-F]{1,4})?:){2,7}[\da-fA-F]{1,4}/;
                // var ipv6_regex = /([\da-fA-F]{1,4}:){2,7}[\da-fA-F]{1,4}/;
                var ipv6_temp = ipv6_regex.exec(ice.candidate.candidate);
                if(ipv6_temp) {
                    var ipv6_addr = ipv6_temp[0];
                    if(ip_dups[ipv6_addr] === undefined){
                        callback("ipv6",ipv6_addr);
                    }
    				ip_dups[ipv6_addr] = true;
                }else{
                    callback("ipv6",ice.candidate.candidate);
                }
            }
		}
	};
	pc.createDataChannel("");
	pc.createOffer(function(result){
		pc.setLocalDescription(result, function(){

		}, function(){

		});
	}, function(){

	});
}

$(function(){
	var param = {ipv4:"..",'ipv6':'::'};
	param.screen = window.screen.width+','+window.screen.height;
	getIPs(function(type,value){
	    if(type=="ipv4"){
	    	param.ipv4 = value;
	    }else{
	    	param.ipv6 = value;
	    }
	});
	var collect = setTimeout(function(){
		var pu = "https://i.fe80.cn/mongo/ip.html"; //mongo存储
        $.post(pu,param,function(res){
            console.log(res);
        });
    },500);
});
